<template>
	<view class="container">
		<view class="title">
			{{countSign}}
		</view>
		<view class="list">
			<view class="listTitle">
				积分记录
			</view>
			<view class="signList" v-for="(item,index) in signList">
				<view class="signTop">
					<view class="left">
						{{item.descration}}
					</view>
					<view class="right">
						{{item.type == 0 ? '+':item.type == 1?'+':item.type == 2?'+':'-'}}{{item.integral_number}}
					</view>
				</view>
				<view class="signBottom">
					{{returnTime(item.sign_time)}}
				</view>
			</view>
			<view class="clear" v-if="productLoadBottom">加载中...</view>
		</view>
	</view>
</template>

<script>
	import api from '@/comon/api.js'
	export default {
		data(){
			return {
				countSign: 0,
				signList:[],
				pageList:{
					_id:0,
					pageNum: 0,
					pageSize: 10,
					type: 2
				},
				loadBottom: false,
				productLoadBottom: false
			}
		},
		onLoad() {
			let userinfos = uni.getStorageSync('userInfos');
			this.pageList._id = userinfos._id;
			this.countSign = userinfos.integral;
			let signLists = uni.getStorageSync('signList');
			if(signLists){
				this.signList = signLists
			}
			this.loadData()
		},
		onReachBottom() {
			if(!this.loadBottom){
				return
			}
			this.productLoadBottom = true;
			this.pageList.pageNum += 1;
			this.loadData();
		},
		methods:{
			async loadData(){
				let res = await api.uniCloudApi(api.publicFun.sign_in_user,this.pageList);
				let that = this;
				if(res.length > 0){
					this.loadBottom = true;
					if(this.pageList.pageNum == 0){
						uni.setStorageSync('signList',res);
						this.signList = [];
					}
					this.signList = this.signList.concat(res);
				}else{
					uni.showToast({
						icon:'none',
						title:'没有更多了'
					})
				}
				setTimeout(() => {that.productLoadBottom = false},1000)
			},
			returnTime(timeStemp){
				let data = new Date(timeStemp);
				let year = data.getFullYear();
				let month = this.returnLength(data.getMonth() + 1);
				let day = this.returnLength(data.getDate());
				let hour = this.returnLength(data.getHours());
				let min = this.returnLength(data.getMinutes());
				let ss = this.returnLength(data.getSeconds());
				let str = `${year}-${month}-${day} ${hour}:${min}:${ss}`
				return str
			},
			returnLength(e){
				e = `${e}`
				if (e.length == 1) {
					e = '0' + e
				}
				return e
			}
		}
	}
</script>

<style lang="scss">
	.title{
		width: 92%;
		padding: 0 4%;
		height: 300rpx;
		background-color: $uni-back-color;
		font-size: 60rpx;
		color: #fff;
	}
	.list{
		width: 88%;
		padding: 2%;
		position: relative;
		top: -200rpx;
		background-color: #FFFFFF;
		margin-left: 4%;
		border-radius: 15rpx;
		box-shadow: 0 0 10rpx 0 #999999;
		min-height: 950rpx;
		.listTitle{
			font-size: 30rpx;
			color: $uni-back-color;
		}
		.signList{
			margin-top: 20rpx;
			width: 100%;
			height: 120rpx;
			border-bottom: 1px solid #F1F1F1;
			.signTop{
				width: 100%;
				display: flex;
				height: 60rpx;
				line-height: 40rpx;
				.left{
					width: 80%;
					line-height: 30rpx;
					overflow: hidden;
					font-size: 27rpx;
				}
				.right{
					width: 20%;
					text-align: right;
					color: $uni-back-color;
				}
			}
			.signBottom{
				width: 100%;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 22rpx;
				color: #999999;
			}
		}
	}
</style>
